package com.flca.frw.util;

import java.io.File;
import java.io.FileFilter;

/**
 * Simple helper class that can be used to filter on an extension(s)
 * @author nly36776
 *
 */
public class FilterByExtension implements FileFilter {

	private String[] extensions;
	
	
	public FilterByExtension(String aExtension) {
		super();
		this.extensions = new String[] {aExtension.trim().toLowerCase()};
	}

	public FilterByExtension(String[] aExtensions) {
		super();
		this.extensions = aExtensions;
		for (int i = 0; i < aExtensions.length; i++) {
			extensions[i] = extensions[i].trim().toLowerCase();
		}
	}

	@Override
	public boolean accept(File aFile) {
		if (aFile.isDirectory()) {
			return true;
		} else {
			String fname = aFile.getName().trim().toLowerCase();
			for (int i = 0; i < this.extensions.length; i++) {
				if (fname.endsWith(this.extensions[i])) {
					return true;
				}
			}
			return false;
		}
	}

}
